package com.web;

import java.io.IOException;

import javax.management.modelmbean.RequiredModelMBean;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.ListIterator;
import java.lang.*;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;

import javax.servlet.http.HttpServletResponse;

import model.LeaveDTO;
import model.PositionDTO;
import model.UserDTO;

import org.apache.log4j.Logger;
import org.omg.CORBA.Request;

import bizlogic.LeaveManager;
import bizlogic.PositionManager;
import bizlogic.UserManager;

/**
 * Servlet implementation class LeaveListServlet
 */
@WebServlet("/leaveeditview")
public class LeaveListServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public LeaveListServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) 
	throws ServletException, IOException {
		processRequest(request,response);
		// TODO Auto-generated method stub
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		processRequest(request,response);
		
		// TODO Auto-generated method stub
	}
	
	private void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		UserDTO us =(UserDTO)request.getSession().getAttribute("user");
		String id = us.getId().toString();
		LeaveManager LM = new LeaveManager();
		ArrayList<LeaveDTO> data = LM.findAllLeaveByUser(id);
		request.setAttribute("Leave", data);
		RequestDispatcher rd = request.getRequestDispatcher("LeaveList.jsp");
		try
		{
			rd.forward(request, response);

		}catch (ServletException e){
			
			e.printStackTrace();
		}catch(IOException e)
		{
			e.printStackTrace();
		}
		
	}
}
